<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绘制矩形</title>
</head>
<body>
  <canvas id="test" width="800" height="400" style="background: #eee;"></canvas>

  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.getElementById('test')
    const context = canvas.getContext('2d')
  
    context.strokeStyle = 'blue'
    context.strokeRect(100, 100, 300, 200)

    context.fillStyle = 'green'
    context.fillRect(100, 100, 300, 200)


  </script>
</body>
</html>